#ifndef GAMEENGINE_H
#define GAMEENGINE_H

#include <QKeyEvent>
#include "../render/Render.h"
#include "../render/core/Shape.h"
#include "../physics/PhysicWorld.h"
#include "../physics/bodies/BasicCar.h"
#include "../physics/bodies/AirPlane.h"
#include <qquaternion.h>

class GameEngine {
public:
	GameEngine();
	~GameEngine();
	void init();
	void loopGame();
	void resize(int w, int h) {
		this->render->resize(w, h);
	}

	Render* getRender() {
		return render;
	}

	virtual void keyReleaseEvent(QKeyEvent* event);
	virtual void keyPressEvent(QKeyEvent* event);
	void mappingBodyToShape(Body* body, Shape* shape) {
		this->bodyMapingShape->insert(body, shape);
	}
protected:
	void doKeyEvent();
	void updateShapeStatusFormBody() {
		QMap<Body*, Shape*>::const_iterator bodyShape;
		for (bodyShape = this->bodyMapingShape->constBegin(); bodyShape != this->bodyMapingShape->constEnd(); ++bodyShape) {
			Body* body = bodyShape.key();
			Shape* shape = bodyShape.value();
			shape->setPosition(*body->getPosition());
			shape->setRotation(body->getRotation());
		}
	}
private:
	Render* render;
	PhysicWorld* world;
	QMap<Body*, Shape*>* bodyMapingShape = new QMap<Body*, Shape*>();

	QElapsedTimer* elapsedTimer = new QElapsedTimer();

	BasicCar* carBody;

	AirPlane* airPlane;

	Camera* camera;
};

#endif